using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace OnlineAnadolu
{
    public partial class Onaylama : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            //CrystalReportViewer1.ReportSource =report;
            //CrystalReportViewer1.Visible = true;

        }

        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            Response.Write("sfd");
        }

        protected void CreateUserWizard1_PreviousButtonClick(object sender, WizardNavigationEventArgs e)
        {
            ////ana sayfa
            //Response.Redirect("default.aspx");
            
            //Button br=(Button)CreateUserWizard1.FindControl("CreateUserButton");
            //br.Visible = false;
        }

        protected void CreateUserWizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            string query = "SELECT [username], [subscribecode] FROM [users] WHERE (([username] = N'" + tb_KullaniciAdi.Text + "') AND ([subscribecode] = N'" + tb_Onay_Kodu.Text + "') AND ([issubscribed] = 0))";
            SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["shoppingConnectionString"].ToString());
            SqlCommand cmd2 = new SqlCommand(query, con2);
            SqlDataAdapter ad2 = new SqlDataAdapter(cmd2);
            DataTable dt2 = new DataTable();
            ad2.Fill(dt2);
            if (dt2.Rows.Count==0)
                    lb_Error.Text = "Boyle birisi bulunamadi";
                else
                {
                    SqlDataSource1.UpdateCommand = "UPDATE users SET password =N'" + tb_Sifre.Text + "', issubscribed =1 WHERE (username = N'" + tb_KullaniciAdi.Text + "')";
                    SqlDataSource1.Update();
                }

            
        }

        protected void tb_Onay_Kodu_TextChanged(object sender, EventArgs e)
        { 
            lb_Error.Text = "";
            try
            {
                string query = "SELECT [username], [subscribecode] FROM [users] WHERE (([username] = N'" + tb_KullaniciAdi.Text + "') AND ([subscribecode] = N'" + tb_Onay_Kodu.Text + "') AND ([issubscribed] = 0))";
                SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["shoppingConnectionString"].ToString());
                SqlCommand cmd2 = new SqlCommand(query, con2);
                SqlDataAdapter ad2 = new SqlDataAdapter(cmd2);
                DataTable dt2 = new DataTable();
                ad2.Fill(dt2);
                if (dt2.Rows.Count == 0)
                    lb_Error.Text = "Boyle birisi bulunamadi";
                else
                    lb_Error.Text = "";
            }
            catch(Exception ex)
            {
                lb_Error.Text = "Onay kodu hatali";
            }
           
            

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string q = "Delete From users where username=nevzat";
            Database db = new Database();
            db.insert(q);
        }
    }
}
